import '../index.dart';

class ThemeChangePage extends StatelessWidget {
  const ThemeChangePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GlobalStyle(
      child: BackgroundStyleWidget(
        child: Scaffold(
          appBar: AppBar(
            title: Text(
              S.of(context).theme,
            ),
            centerTitle: true,
          ),
          body: ListView(
            //显示主题色块
            children: Global.themes.map<Widget>((e) {
              return GestureDetector(
                child: Padding(
                  padding:
                      const EdgeInsets.symmetric(vertical: 5, horizontal: 16),
                  child: Container(
                    color: e,
                    height: 40,
                  ),
                ),
                onTap: () {
                  //主题更新后，MaterialApp会重新build
                  Provider.of<ThemeModel>(context, listen: false).theme = e;
                },
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}
